package com.itheima.web.controller;

import cn.hutool.core.util.StrUtil;
import com.itheima.domain.db.Freeze;
import com.itheima.domain.db.UserInfo;
import com.itheima.vo.MovementVo;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.UserInfoVo;
import com.itheima.web.manager.AdminManager;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Guanxing
 * @date 2021/9/30
 */
@RestController
public class UserController {

    @Autowired
    private UserManager userManager;

    //查询用户
    @GetMapping("/manage/users")
    public PageBeanVo findUsers(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        return userManager.findUsers(page, pagesize);
    }

    //查询用户详情
    @GetMapping("/manage/users/{userId}")
    public UserInfoVo findUserById(
            @PathVariable("userId") Long userId
    ) {
        return userManager.findById(userId);
    }

    //查询视频列表
    @GetMapping("/manage/videos")
    public PageBeanVo findVideoByUserId(
            @RequestParam(defaultValue = "1", name = "backstage") Integer pageNumber,
            @RequestParam(defaultValue = "10", name = "pagesize") Integer pagesize,
            Long uid
    ) {
        return userManager.findVideoByUserId(pageNumber, pagesize, uid);
    }

    //动态列表
    @GetMapping("/manage/messages")
    public PageBeanVo findMovementList(
            @RequestParam(defaultValue = "1", name = "backstage") Integer pageNumber,
            @RequestParam(defaultValue = "10", name = "pagesize") Integer pageSize,
            Long uid,
            String state
    ) {
        Integer stateInt = null;
        if (StrUtil.isNotEmpty(state) && !StrUtil.equals("''",state)) {
            stateInt = Integer.valueOf(state);
        }

        return userManager.findMovementList(pageNumber, pageSize, uid, stateInt);
    }

    //动态详情
    @GetMapping("/manage/messages/{movementId}")
    public MovementVo findByMessages(
            @PathVariable String movementId
    ) {
        return userManager.findMovementById(movementId);
    }

    //评论列表
    @GetMapping("/manage/messages/comments")
    public PageBeanVo findByMessages(
            String messageID, //动态id
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) {
        return userManager.findCommentByMovementId(page,pagesize,messageID);
    }

    //用户冻结操作
    @PostMapping("/manage/users/freeze")
    public Map freeze(
            @RequestBody Freeze freeze) {
        return userManager.freeze(freeze);
    }

    //用户解冻操作
    @PostMapping("/manage/users/unfreeze")
    public Map unfreeze(@RequestBody Freeze freeze) {
        return userManager.unfreeze(freeze);
    }

}
